package com.rui.study.commons.study.support.configuration;

import com.rui.study.commons.study.support.factory.SimpleThreadFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class SimpleThreadPoolExecutorConfiguration {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        DelayQueue delayQueue = new DelayQueue();
        ThreadFactory threadFactory = new SimpleThreadFactory("my-task");
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                5, 10, 30,
                TimeUnit.SECONDS,
                delayQueue,
                threadFactory);
        return threadPoolExecutor;
    }
}
